New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Java Panama FFI prototype experiments (DO NOT MERGE) #11095
Draft
alanpaxton
wants to merge
55
commits into
facebook:main
Choose a base branch
from
alanpaxton:eb-1680-panama-ffi
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alanpaxton
force-pushed
the
eb-1680-panama-ffi
branch
from
January 25, 2023 16:15
d7350d8
to
5dd3543
Compare
Implementing a get() using FFI We are building and accessing function(s) (1) Still working out why the data is not coming back, as it has been read into the PinnableSlice and copied to the rocksdb_output_slice (2) Make classes with VarHandles as members for repeated, efficient access to slices..
- why do we need to pass memory addresses ? - lots of refactor/cleanup yet to do..
Pull out MethodHandles, MemoryLayouts and VarHandles used by the RocksDB FFI so that the core of the methods in FFIDB (get(), etc) are compact and readable. Make the first test check the returned value of a key originally written by the old API.
Change FFI API into a byte[]-based one from String, consistent with the current API (String was just for initial testing) Make reset() of pinnable slice public (it shoud be, and jmh benchmarks need it to be) Build configurations need updated to build RocksDB JAR in java 19 and enable preview features. Same for jmh test jar, and invocations
This should mean that allocation is done with a default Cleaner linked to the session which should release the allocated segments via GC. We seem to be getting away with it in jmh GetBenchmark.java
JMH benchmarks are sufficiently good that we have implemented a paranoid test confirming that multiple get()s are all really working and fetching back from a database. Start commenting the important methods and classes.
implement it.
Investigate whether mutiple calls over FFI are a problem; we have to do 2 calls per op when using pinnable slices, 2nd to release the slice. So we implement a copying get (getOutputSlice) that obviously doesn’t need to hold a pinnable slice back in Java; It may be more efficient for small value sizes.
Describes what we have done and contains some results.
These are still part of exploring why FFI implementations are slightly slower than JNI.
Summary at current state, where we are still at a loss as to wny performance is not as good as with JNI. We have tested some hypotheses, but none is able to account for the difference.
Allocate a single segment that contains both input and output slice structs
Avoid copying and recycling for a potentially fairer benchmarking.
Since we are not using it as heavily; and because our recycling allocation is not happy when we hold something long-lived.
Allocate one separately at the start reset() it when needed dispose at the end
Try performance again
Type checking is tighter. Does it help performance ? It can’t hurt.
alanpaxton
force-pushed
the
eb-1680-panama-ffi
branch
from
March 9, 2023 15:22
16e4ec3
to
bc593a1
Compare
On M1 Max, maybe 1% performance gain with 64k value size. There’s something there, if not much.
We can just fill the key segment with the bytes we need.
Make all VarHandle(s) conform to exact invocation.
This reverts commit a1f158f.
Reflect the fact performance is now very nearly equal in the writeup, acknowledge help from Maurizio at Oracle. (panama-dev).
Analyse performance cost of the extra FFI call to release a pinnable slice versus the extra copy into a foreign memory segment allocated on the Java side. 1k-4k break even.
First part of replacement is to not do anything with the replaced SliceBuffer, just check the CI run..
facebook-github-bot
pushed a commit
that referenced
this pull request
Feb 20, 2024
Summary: We did some experimental work with FFI and native memory as a potential improvement to the Java API. The work lives (unmerged) in #11095 This is the report text from that branch, extract as a blog post. Along with some supporting files (png, pdf of graphs). Pull Request resolved: #11760 Reviewed By: hx235 Differential Revision: D53943442 Pulled By: ajkr fbshipit-source-id: 7c9f800e25be22c10e736cdd3b0d65422ecfc826
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Experimental implementation of Java 19 PREVIEW API JEP 424, aka Project Panama based RocksDB Java API.
See Java Panama FFI prototype Detailed Description
Goals
get()
)PinnableSlice
at API level)Non-Goals